package com.ai.vita.redis.client;

import redis.clients.jedis.Jedis;

import java.util.HashMap;
import java.util.Map;

/**
 * redis客户端代理.
 */
public class RedisClient {

    private static Long MAX_RECORD_NUMBER = 100L;

    private static Integer MAX_KEY_NUMBER = 100;

    private static Integer MAX_DB_NUMBER = 20;

    private static Map<String, Jedis> CLIENT_MAP = new HashMap<String, Jedis>();

    public static Jedis get(String name, String host, int port, String auth){
        Jedis jedis = CLIENT_MAP.get(name);
        if(jedis == null || jedis.getClient().isBroken()){
            jedis = new Jedis(host, port);
            if(auth != null){
                jedis.auth(auth);
            }
            CLIENT_MAP.put(name, jedis);
        }else if(!jedis.isConnected()){
            jedis.connect();
        }
        return jedis;
    }

    public static Long getMaxRecordNumber(){
        return MAX_RECORD_NUMBER;
    }

    public static Integer getMaxKeyNumber(){
        return MAX_KEY_NUMBER;
    }

    public static Integer getMaxDbNumber(){
        return MAX_DB_NUMBER;
    }

}
